package com.atguigu.gmall.payment;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.response.AlipayTradePagePayResponse;

import java.util.HashMap;
import java.util.Map;

/**
 * @Auther 赵乾坤
 * @Date 2021-01-11 20:21
 */
public class PaymentDemo {

    //付款方（消费者）（同学们）     收款方（商家）（尚品汇）    支付宝（平台）   三方
    //连接支付宝微服务
    public static void main(String[] args) throws Exception {////支付宝公司 SDK 包  Apache HttpClient

        AlipayClient alipayClient = new DefaultAlipayClient(
                        "https://openapi.alipaydev.com/gateway.do",//支付宝平台接口的URL
                "2021000116695913",//收款方的帐户
                "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCRkgdLWloZARhg1veF8IEQHMxTqvEWd1617Mi1K0uGU1SQnR+TlP9orptxMixC1RkJt0rSFwCzajFELZNQYa25iYobMt0tsCYDwTYtbX3/nC5KshCYHU+r8t1e8+b2NgQXy8bZsb2YjyJUEFc/AAyjgCKbyrvlqmEw0y9kahCOwbtDv19rlEAhqHUgJtvJEzz2UcHIXtteFd/s48vPUekhevDxvaSOs+5NfstmEvjzFc404IXOxLD9m2X3lVmd7j4V+Yf8NOTpHgx3YmPRp2OcyHixqMFuR7eE5oJzUdeM1vg7Z3XY+PT08TqHJRV/j8/xldvuBB82XBnk/1d/FDJRAgMBAAECggEAGii0uNzOrgmdWOGob2BNwRh7u1lPo6rl0Slw0+Wo18Wnv6kMoJe44hXmhwvuGkBzFGTkxCYwEQ23Nro968bx0hKeR873IhuyaSBSXQ19A+8L/o5LHxq9U3f8QfDwgzQnviL3Y+1l1cF6+MJK+15F5yfCkF55L4dTmdOJg7Dvssdjx87K59pdi3vgMsD3wnzGRsmvv4X5amsRbewt3Smxho4C+sRrfr8psoRvz5OHAHlPP3Ik3UFVhsGlD9JLxej1LM84UwRrtCOw4tuJonRrgCfhZD6OK5gdQXQVoS6BzR88dfUa6h1vpK9chx5OGtEh8Kus5KR3LPagaY+Dwx80cQKBgQD70mGKun/OlLAAJbdJK//Q8bLXmad/y47bKVtTqlk6wnwYLyilhMvAgaPVOPgH1A3FzO0TFtYjlYDtUcAJMczecUWAmHr503nQ97jHgJtFajuhWTN5y9K5Ga2Zx1AUcnPgYZ9vU72x8n6Fa58VsOGHK+yXy/WdNKGjW4B14ONGZQKBgQCT/FeexOuMDTus8CaGNqNfEnfc6w3aCAdWTPFmWxtb32hen4LXBEjQLkdhTBhi1DRyunqak3POggKx1BUZo9O/d2Tm+V8KcHOKU/CM569/EWoMtTZXZBCXsqTEeTnB+xWm/Ix31QV9LQgEJ9STHkcPJp4q+eDdDg7GF2uBokzXfQKBgQCWyewkkPZ08e3NuMfepd0h9Yi8t0JoMLDTJRmNqMSTfd+m754sNq93D2nWBK3oqh6xIbuYIaWKWzx/XuNZ3hsp27Pdg/CnZe1cpulbdPQFBc69F9fOB7GfqvOb0JBwHfSrGGnK1N8TDfya0c3JxEfXlAKxBq2FO/3J/sGWVFpjTQKBgB3bsTYYl0n3tY2sGqnDxmy9Ri/twSq3qftQpPg486kyx1UoK/cEJ0jRvZc1CkqOdFKdq3UawSfudWq51tQIiQW9qj8sG2/4xmcnjoZvjKo/sj0EJwW06+AfrDz0FKI97d12YUUgVu4tsstb2fkhB8dXzFvxdNxFJNf1C7zpKUXlAoGAda3ZxnHEoLqXLh2ffFi1XU+MPtZsUTXLurphwMvWXNrkY69Yd2Q4k4tQOxDusds+cwnysOMQL2emjwlZJSzf2N/seL3hELIEACBEcwXl+9SVnV+kwkxtb5X1SC9UIJuGSc7S0SEsAexVkWz31gIShFAdaSCloKUCnnCo6NK3ZRg=",//收款方 私钥
                "json",//发送格式
                "GBK",//编码
                "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlxpu+twCGEblFQdWNcNkvn+gbxIMpLDAfytBm9wG33XPPQV/QArJSGDZhsz/fw8IeA6WqYQxpkcV+DzjHcwSt0GKRjkcJbNgyaJHo9NzG/1R/mLNNQWjBqBJPJVAGxHoNHglKIgwwbkIfQO4gjxBA5r4ZgHbPMMonVQqtfKUZcxgMxFNu9mxHuiI9OquCXhgx+yXAX/4+4evks1WS0k/h5Dgxtx/QXV4i+3GDXtOP4IIwPTwo6qlPM1LmxIdvctAD5nW2YJlorXUiQAHnk127VBysKrhLyy/zHWhfG8E5e63rLsUAW6F8Gvn/dDlyZ3Q0I1KJLmwXLj8l7MOt0tbAQIDAQAB",//支付宝公钥
                "RSA2");//RSA2 加密方式 三个外国人  号称全世界最安全加密方式
        AlipayTradePagePayRequest
                /*        <form name="punchout_form" method="post"
action="https://openapi.alipaydev.com/gateway.do?charset=UTF-8&method=alipay.trade.page.pay&sign=e2oXOyOm1Vzv769BdRLagcUbbTCS5iBmiQpawO7Sb5UN32grIf7eKaZgw%2BzQ%2FeYCIiW7qRDc%2B2wqMDvfpsXuGpsyfiK%2BKwqdMHXE6RFsiGbqG2a6AvzMCdGYFatBHNXcCOSNxzZBeONb9MwNJKe7Tdj27%2B9Tcr%2BABL1vnAFbQNYa7RfB4CUY%2BhmTj0pViM9%2FOPvhat4t2qOuwh%2BVOWfZvSay9%2BXPqFoOUiJj0925RWoEDmvaRWZBEOKvyTPxw3qG%2FSCNeL1h2e3LVe%2BWelyB9B1dMwkobscJvAZC4qsWJxXrQkJgkersTrilJtcQTGnQjLnh2nh5N8o%2BxhmqxTEP7w%3D%3D&version=1.0&app_id=2016102100732915&sign_type=RSA2&timestamp=2021-01-11+14%3A31%3A11&alipay_sdk=alipay-sdk-java-4.8.73.ALL&format=json">
<input type="hidden" name="biz_content" value="{&quot;out_trade_no&quot;:&quot;tyreuyrggjyhtdggh6y5rtk7dsafas&quot;,&quot;total_amount&quot;:&quot;10&quot;,&quot;subject&quot;:&quot;我要买手机&quot;,&quot;product_code&quot;:&quot;FAST_INSTANT_TRADE_PAY&quot;}">
<input type="submit" value="立即支付" style="display:none" >
</form>
<script>document.forms[0].submit();</script>*/


                request = new AlipayTradePagePayRequest();
        Map map = new HashMap<>();
        map.put("out_trade_no", "tyreuyrggjyhdggh6y5rtk7dsafas");//生成订单号
        map.put("product_code","FAST_INSTANT_TRADE_PAY");//快熟及时交易
        map.put("total_amount","10");//总金额
        map.put("subject", "我要买手机");//标题
        request.setBizContent(JSONObject.toJSONString(map));
        AlipayTradePagePayResponse response = alipayClient.pageExecute(request);
        if(response.isSuccess()){
            String body = response.getBody();
            System.out.println(body);
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
        }
    }

}
